
from flask import Flask

from flask_cors import CORS

from models import db
from views.users import user_bp
from views.channel import channel_bp
from views.comments import comments_bp
from common.uitils.jwt_auth import jwt_authentication


def create_flask_app(config):
    app = Flask(__name__)
    app.config.from_object(config)
    db.init_app(app)
    cors = CORS(app)

    # 注册蓝图
    app.register_blueprint(user_bp)
    app.register_blueprint(channel_bp)
    app.register_blueprint(comments_bp)

    # 使用请求钩子验证token
    app.before_request(jwt_authentication)

    return app
